//
//  SetUpView.m
//  afn
//
//  Created by mac on 2018/5/9.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "SetUpView.h"
#import "SetUpTableViewCell.h"

@implementation SetUpView

-(void)creatView{
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    _tableView.backgroundColor=_LightGrey;
    
    UIButton *btn=[UIButton new];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-60);
        make.height.mas_equalTo(50);
    }];
    btn.backgroundColor=ColorWithRGB(252, 83, 86);
    [btn setTitle:@"退出登录" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    btn.layer.cornerRadius=4;
    btn.titleLabel.font=[UIFont systemFontOfSize:16];
    [btn addTarget:self action:@selector(pushToLogin:) forControlEvents:UIControlEventTouchUpInside];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SetUpTableViewCell *cell=[[SetUpTableViewCell alloc] init];
    
    if (indexPath.row==0) {
        [cell creatView];
    }if (indexPath.row==1) {
        [cell creatView2];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return 111;
    }
    return 162;
    
}
-(IBAction)pushToLogin:(UIButton *)tap{
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    if ([defaultManager removeItemAtPath:_userModelFile error:nil]) {
        //退出的时候删除别名
//        [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
//            if (iResCode == 0) {
//                NSLog(@"删除别名成功");
//            }
//        } seq:1];
        
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults removeObjectForKey:@"token"];
        
        [gongju svpInfo:@"你已经退出登录状态"];
        [self.viewController.navigationController popViewControllerAnimated:YES];
    }
    
    
}


@end
